package day10.CodeTransferTest;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class Test3 {
    public static void main(String[] args) {
        /*
        abc中文喆镕
        f8文件，保存gbk编码
        f7文件，保存unicode编码
         */
        String str = "abc中文喆镕";
        String path = "/Users/hao/Desktop/abc/";
        try {
            f(str, "UTF-8", path+"f7");
            f(str, "gbk",path+"f8");
            System.out.println("传输成功");
        } catch (IOException e) {
            System.out.println("传输失败");
            e.printStackTrace();
        }


    }
    public static void f(String str, String encoding, String path) throws IOException {
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path), encoding);
        out.write(str);
        out.close();
    }
}
